﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class tbCTNH
    {
        private int sott;

        public int Sott
        {
            get { return sott; }
            set { sott = value; }
        }
        private string mamh;

        public string Mamh
        {
            get { return mamh; }
            set { mamh = value; }
        }
        private string mancc;

        public string Mancc
        {
            get { return mancc; }
            set { mancc = value; }
        }
        private string ngaynhap;

        public string Ngaynhap
        {
            get { return ngaynhap; }
            set { ngaynhap = value; }
        }
        private int soluong;

        public int Soluong
        {
            get { return soluong; }
            set { soluong = value; }
        }
        private long giamua;

        public long Giamua
        {
            get { return giamua; }
            set { giamua = value; }
        }

        private string ngaybt;

        public string Ngaybt
        {
            get { return ngaybt; }
            set { ngaybt = value; }
        }
        private string ngaykt;

        public string Ngaykt
        {
            get { return ngaykt; }
            set { ngaykt = value; }
        }

        DBAccess db = new DBAccess();
        public DataTable dalDSCTNH()
        {
            string query = "HienThiCTNH";
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@SoTT", Sott);
            return db.GetDataTable(query, CommandType.StoredProcedure, param);
        }

        public bool dalThemCTNH()
        {
            bool res = false;
            string query = "ThemCTNH";
            SqlParameter[] param = new SqlParameter[5];
            param[0] = new SqlParameter("@MaMH", Mamh);
            param[1] = new SqlParameter("@MaNCC", Mancc);
            param[2] = new SqlParameter("@NgayNhap", Ngaynhap);
            param[3] = new SqlParameter("@SoLuong", Soluong);
            param[4] = new SqlParameter("@GiaMua", Giamua);
            res = db.DoExcecute(query, CommandType.StoredProcedure, param);
            return res;
        }

        public bool dalSuaCTNH()
        {
            bool res = false;
            string query = "SuaCTNH";
            SqlParameter[] param = new SqlParameter[3];
            param[0] = new SqlParameter("@SoLuong", Soluong);
            param[1] = new SqlParameter("@GiaMua", Giamua);
            param[2] = new SqlParameter("@SoTT", Sott);
            res = db.DoExcecute(query, CommandType.StoredProcedure, param);
            return res;
        }

        public bool dalXoaCTNH()
        {
            bool res = false;
            string query = "XoaCTNH";
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@SoTT", Sott);
            res = db.DoExcecute(query, CommandType.StoredProcedure, param);
            return res;
        }

        public DataTable dalTKMatHangNhap()
        {
            string query = "TKMatHangNhap";
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@NgayBT", Ngaybt);
            param[1] = new SqlParameter("@NgayKT", ngaykt);
            return db.GetDataTable(query, CommandType.StoredProcedure, param);
        }
    }
}
